package com.dingwei.superiordiary.mvp.presenter;

import android.text.TextUtils;

import com.dingwei.superiordiary.base.MyBaseBean;
import com.dingwei.superiordiary.bean.FailsBean;
import com.dingwei.superiordiary.custom.myCallback;
import com.dingwei.superiordiary.mvp.view.Contract;
import com.lihao.baselibrary.base.BaseActivity;
import com.lihao.baselibrary.base.URLS;
import com.lihao.baselibrary.base.basePresenter;

import org.xutils.http.RequestParams;
import org.xutils.x;

/**
 * Created by lihao on 2017/9/12.
 */

public class FillInLogisticsNumberPresenter extends basePresenter {

    private Contract.FillInLogisticsNumberView fillInLogisticsNumberView;

    public FillInLogisticsNumberPresenter(Contract.FillInLogisticsNumberView view) {
        super(view);
        this.fillInLogisticsNumberView = view;
    }

    public void submit(String id, String express, String tel, String express_bill) {
        if (TextUtils.isEmpty(express_bill)) {
            showToast("请输入快递单号");
            return;
        }
        if (TextUtils.isEmpty(tel)) {
            showToast("请输入收货人电话");
            return;
        }
        if (TextUtils.isEmpty(express)) {
            showToast("请选择快递公司");
            return;
        }
        RequestParams rp = new RequestParams(URLS.HOST+URLS.SERVICE_DELIVERY);
        rp.addBodyParameter("sessionid", BaseActivity.value.getToken());
        rp.addBodyParameter("id", id);
        rp.addBodyParameter("express", express);
        rp.addBodyParameter("express_bill", express_bill);
        rp.addBodyParameter("tel", tel);
        x.http().post(rp, new myCallback(BaseActivity.context, MyBaseBean.class, rp) {
            @Override
            public void back(MyBaseBean baseBean, String result) {
                showToast(baseBean.message);
                fillInLogisticsNumberView.submitSuccess();
            }

            @Override
            public void fail(FailsBean baseBean, String result) {
            }
        });
    }
}
